<template>
  <div class="statistics">
    <div v-if="showShare">
      <div class="statistics-table">
        <el-input
          placeholder="输入要搜索的平台名称"
          v-model="mobile"
          clearable
          class="plat-ipt"
        >
          <i slot="suffix" class="el-icon-search" @click="onSearch"> </i>
        </el-input>
        <el-select v-model="value" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-button type="primary" @click="addMsgShare" class="add-btn"
          >添加分配短信</el-button
        >
      </div>

      <el-table
        :data="tableData"
        :header-cell-style="headerCellStyle"
        style="width: 100%"
      >
        <el-table-column prop="name" label="平台名称"> </el-table-column>
        <el-table-column prop="type" label="平台类别"> </el-table-column>
        <el-table-column prop="sign" label="短信签名"></el-table-column>
        <el-table-column prop="num" label="可用数量"> </el-table-column>
        <el-table-column label="操作" header-align="right" align="right">
          <template>
            <span class="edit-style" @click="editMsg">
              编辑
            </span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <add-msg v-if="showAdd" @toggle="toggle"></add-msg>
    <edit-msg v-if="showEdit" @toggle="toggle"></edit-msg>
  </div>
</template>

<script>
import AddMsg from './add-msg.vue'
import EditMsg from './edit-msg.vue'
export default {
  name: 'share',
  components: {
    AddMsg,
    EditMsg
  },
  props: {
    tableData: {
      type: Array,
      default() {
        return [
          {
            id: 0,
            name: '系统短信',
            type: '系统',
            sign: '【】',
            num: 0
          }
        ]
      }
    }
  },
  data() {
    return {
      showShare: true,
      showAdd: false,
      showEdit: false,
      value: '0',
      options: [
        {
          value: '0',
          label: '全部'
        },
        {
          value: '1',
          label: '发送成功'
        },
        {
          value: '2',
          label: '发送失败'
        }
      ],
      bodyStyle: {
        background: '#fffbf3',
        color: '#efb44a',
        padding: '0 30px',
        fontSize: '14px',
        borderRadius: '4px'
      },
      headerCellStyle: {
        background: '#f7f8fa',
        height: '40px'
      },
      mobile: ''
    }
  },
  methods: {
    onSearch() {
      console.log(this.mobile)
    },
    toggle(e) {
      if (e === 'add') {
        this.showAdd = false
        this.showShare = true
      } else if (e === 'edit') {
        this.showEdit = false
        this.showShare = true
      }
    },
    addMsgShare() {
      this.showShare = false
      this.showAdd = true
    },
    editMsg() {
      this.showEdit = true
      this.showShare = false
    }
  }
}
</script>

<style lang="scss" scoped>
.statistics {
  .el-card {
    border: 1px solid #fec;
    margin-bottom: 30px;
    color: #efb44a;
    .card-item {
      line-height: 32px;
    }
  }
  .statistics-table {
    // display: flex;
    .plat-ipt {
      width: 300px;
    }
    .add-btn {
      float: right;
    }
  }
}

.el-select {
  margin-left: 30px;
}

.statistics-table {
  margin-bottom: 30px;
}

.edit-style {
  color: #3296fa;
  cursor: pointer;
}
::v-deep .el-input__suffix {
  display: flex;
  align-items: center;
  cursor: pointer;
}
</style>
